{% extends "default.html" %}

{% block content %}
<div class="title">
	Administraci&oacute;n Adquisiciones
</div>
<div class="content">
	<div>Adquisiciones de mercader&iacute;a registrados</div>
	<div>
		<table id="itemtemplate_table">
			<tr>
				<th>Proveedor</th>
				<th>Fecha</th>
				<th>Comentario</th>
				<th>Estado</th>
				{% if request.vendor.is_owner %}
					<th>Acciones</th>
				{% endif %}
			</tr>
			{% if request.obtainments %}
				{% for o in request.obtainments %}
				<tr>
					<td>{{ o.provider.user.first_name }} {{ o.provider.user.last_name }}</th>
					<td>{{ o.date }}</td>
					<td>{{ o.comment }}</td>
					<td>
						{% if o.closed %}
						<div class='closed'>Cerrado</div>
						{% else %}
						<div class='open'>Abierto</div>
						{% endif %}
					</td>
					{% if request.vendor.is_owner %}
						<td>
							{% if o.closed %}
							{% else %}
								<a href="/obtainment/delete/{{ o.id }}">Eliminar</a> <a href="/obtainment/close/{{ o.id }}/">Cerrar</a>
							{% endif %}
						</td>
					{% endif %}
				</tr>
				{% endfor %}
			{% else %}
				<tr>
					<td colspan="5">
						No se han registrado adquisiciones
					</td>
				</tr>
			{% endif %}
		</table>
	</div>
	<div>Puede registrar una adquisici&oacute;n ingresando la siguiente informaci&oacute;n</div>
	<form action="/obtainment/register/" method="post">
		<table id="itemtemplate_table_register">
			<tr>
				<th>Proveedor</th>
				<td>
					{% if request.providers %}
						<select name="provider">
						{% for p in request.providers %}
							<option value="{{ p.id }}">{{ p.user.first_name }} {{ p.user.last_name }}</option>
						{% endfor %}
						</select>
					{% else %}
					No hay proveedores registrados<br>
					Registre un proveedor <a href="/staff/providers/">aqu&iacute;</a>
					{% endif %}
				</td>
			</tr>
			<tr>
				<th>Fecha de inicio</th>
				<td>{% now "d \de F \de Y" %}</td>
			</tr>
			<tr>
				<th>Comentario</th>
				<td>
					<textarea name="comment"></textarea>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="submit" value="Registrar">
				</td>
			</tr>
		</table>
	</form>
</div>
{% endblock %}